package one;

public class ClassAndObject {
    public static class Student {
        //成员变量
        String name;
        int age;
        String className;
        String stuId;
        //方法
        void study(){
            Student zs = new Student();
            zs.name = "张S";
            System.out.println(this.name+"在学习...");
            System.out.println(zs.name+"在学习...");
            zs.sayHi();
        }
        void sayHi(){
            System.out.println("大家好，我叫"+this.name+"，今年"+this.age+"岁了，所在 班级为"+this.className+"，学号为:"+this.stuId);
        }
        void playWith(String anotherName){
            System.out.println(this.name+"正在和"+anotherName+"一起玩...");
        }
    }
    public static class StudentTest {
        public static void main(String[] args) {
    //创建一个学生对象
            Student zs = new Student();
    //访问成员变量
            zs.name = "张三";
            zs.age = 24;
            zs.className = "jsd2302";
            zs.stuId = "001";
    //调用方法
            zs.study();
            zs.sayHi();
            zs.playWith("李四");
            Student ls = new Student();
            ls.name = "李四";
            ls.age = 25;
            ls.className = "jsd2302";
            ls.stuId = "002";
            ls.study();
            ls.sayHi();
            ls.playWith("张三");

            //1)创建了一个学生对象
            //2)给所有成员变量赋默认值
            Student ww = new Student();
            ww.study();
            ww.sayHi();
            ww.playWith("张三");
        }
    }
}
